
<template>
  <div style="height: 100%; width: 100%; position: relative">
    <div class="pagetop">
      <template>
        <div style="width: 100%">
          <div style="float: left; width: 50%">
            <table style="font-size: 12px" class="table1style">
              <tr>
                <td>报告单元</td>
                <td>
                  <rm-ddl-rptunit :appendtobody="true" v-model="rptunitid" @change="rptunitchange" filterable
                    :defaultflag="'1'"></rm-ddl-rptunit>
                </td>
              </tr>
            </table>
          </div>
          <div style="float: left; width: 50%">
            <table style="float: right">
              <tr>
                <td>
                  <el-button type="primary" icon="el-icon-search" @click="initialList">查询</el-button>
                </td>
                <td>
                  <el-button icon="el-icon-plus" @click="operatemdl(1)" v-has="'PADD'">新增</el-button>
                </td>
                <td>
                  <el-button icon="el-icon-delete" @click="operatemdl(2)" v-has="'PDELETE'">删除</el-button>
                </td>
                <td>
                  <el-button icon="el-icon-document" @click="saverecord()">保存</el-button>
                </td>
                <el-button icon="el-icon-document" @click="CopyShow()" v-has="'PADD'">复制</el-button>
                <td>
                  <el-button icon="el-icon-upload2" @click="ExportCsv()" v-has="'PEXPORT'">导出</el-button>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </template>
    </div>
    <div class="pagecenter">
      <div class="middle-center" style="height: 100%">
        <vxe-table show-overflow ref="xTable" height="auto" :loading="loading"
          :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }" fit :data.sync="tableData"
          :keyboard-config="keyConfig" show-header-overflow :row-class-name="rowClassName" @cell-dblclick="opendialog"
          highlight-current-row highlight-hover-row resizable border size="mini" @edit-closed="EditClose"
          @edit-actived="CellActive" @current-change="currentChangeEvent" :mouse-config="{ selected: true }">
          <vxe-table-column type="index" title="NO." width="40" header-align="center" align="center"></vxe-table-column>
          <vxe-table-column field="checktype" title="条件类型" width="100" header-align="center"
            :edit-render="{ name: 'select', options: conditiontypeoptions }"> </vxe-table-column>
          <vxe-table-column field="actions" title="满足条件时" width="110" header-align="center"
            :edit-render="{ name: 'select', options: conditionarriveoptions }" align="center"> </vxe-table-column>
          <vxe-table-column field="ruledisplay" title="组合条件（双击开窗编辑）" width="400" header-align="center">
          </vxe-table-column>
          <vxe-table-column field="logcontent" title="备注说明（双击开窗编辑）" width="160" :edit-render="{ name: 'input' }"
            header-align="center"></vxe-table-column>
          <vxe-table-column field="logflag" title="禁止使用" width="70" header-align="center" align="center">
            <template v-slot="{ row }">
              <el-checkbox v-model="row.logflag" true-label="1" false-label="0"></el-checkbox>
            </template>
          </vxe-table-column>
          <vxe-table-column field="checkrules" title="组合条件（双击开窗编辑）" width="400" header-align="center"> </vxe-table-column>
          <vxe-table-column field="onlyautochk" title="仅自动审核使用" width="100" header-align="center" align="center">
            <template v-slot="{ row }">
              <el-checkbox true-label="1" false-label="0" v-model="row.onlyautochk"></el-checkbox>
            </template>
          </vxe-table-column>
        </vxe-table>
      </div>
    </div>
    <el-dialog title="组合审核条件向导" v-el-drag-dialog :close-on-click-modal="false" :visible.sync="outerVisible" height="500px"
      width="1010px">
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :title="dialogtitle"
        :before-close="cancelinnerdialog" :visible.sync="dialogTableVisible" v-if="dialogx">
        <rm-pop-common @change="popcomchange" @cancel="cancelinnerdialog" :datatype="dataclass"></rm-pop-common>
      </el-dialog>
      <el-form>
        <el-row>
          <div style="width: 100%; float: left">
            <el-input type="textarea" v-model="dialogtopdata" readonly="readonly" disabled="disabled"
              id="topdiv"></el-input>
          </div>
          <div style="width: 100%; float: left; margin-top: 5px">
            <el-input type="textarea" v-model="dialogmiddledata" ref="middledataautofocus" id="middiv"
              @input="targetinput"></el-input>
          </div>
        </el-row>
        <el-row>
          <div style="height: 440px; border: 1px solid #ccc; margin-top: 5px">
            <div style="width: 100%; float: left; height: 100%">
              <div style="position: absolute; right: 255px; left: 0px; overflow: auto">
                <div style="width: 100%; float: left; height: 40px">
                  <div style="width: 60%; float: left">
                    <el-form>
                      <el-form-item label="项目快速查找" label-width="120">
                        <el-input v-model="quicklysearch" style="width: 250px" placeholder="报告项目代码或报告项目名称或缩写"
                          @keyup.enter.native="PopListSearch"></el-input>
                      </el-form-item>
                    </el-form>
                  </div>
                  <div style="width: 40%; float: left; margin-top: 5px">
                    <el-button @click="savedialog" icon="el-icon-document">确 定</el-button>
                    <el-button @click="outerVisible = false" :autofocus="true" icon="el-icon-close">取 消</el-button>
                  </div>
                </div>
                <div style="width: 100%; float: left; height: 390px">
                  <vxe-table show-overflow ref="xTable2" height="auto" row-id="id" :loading="loading"
                    :select-config="{ reserve: true }" :data.sync="poptableData" show-header-overflow
                    highlight-current-row highlight-hover-row resizable border @cell-click="popcurrentChangeEvent"
                    size="mini">
                    <vxe-table-column type="index" title="NO." width="50"></vxe-table-column>
                    <vxe-table-column field="itemcode_en" title="英文缩写" width="100" sortable
                      header-align="center"></vxe-table-column>
                    <vxe-table-column field="rpt_itemname" title="报告项目名称" width="130" sortable
                      header-align="center"></vxe-table-column>
                    <vxe-table-column field="itemtips" title="项目备注" width="140" sortable
                      header-align="center"></vxe-table-column>
                    <vxe-table-column field="itemclassname" title="项目归类" width="90" sortable
                      header-align="center"></vxe-table-column>
                    <vxe-table-column field="instrclassname" title="仪器类别" width="80"
                      header-align="center"></vxe-table-column>
                    <vxe-table-column field="rpt_itemcode" title="报告项目代码" width="100"
                      header-align="center"></vxe-table-column>
                  </vxe-table>
                </div>
              </div>
            </div>
            <div style="width: 255px; float: left; height: 100%; position: absolute; right: 0px">
              <div style="text-align: center; position: realative">
                <table style="text-align: center">
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('+', '1')">+</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('-', '1')">-</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('*', '1')">*</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('/', '1')">/</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('>', '1')">&gt;</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('>=', '1')">&gt;=</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('<', '1')">&lt;</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('<=', '1')"> &lt;=</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('(', '1')">(</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate(')', '1')">)</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('and', '1')">AND</el-button>
                    </td>
                    <td>
                      <el-button style="width: 52.5px; margin: 4px" @click="operate('or', '1')"> OR</el-button>
                    </td>
                  </tr>
                </table>
                <table>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('年龄', '-1')">年龄</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目 数值结果', '-1')">任意项目 数值结果</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('性别', '2')">性别</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目 文字结果', '-1')">任意项目 文字结果</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('病人类型', '2')">病人类型</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px; text-align: center" @click="operate('任意项目 危急值标志', '-1')">任意项目
                        危急值标志</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('科室', '2')"
                        @contextmenu.prevent.native="rightEvent('科室')">科室</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目 复查标志', '-1')">任意项目 复查标志</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('标本类型', '2')"
                        @contextmenu.prevent.native="rightEvent('标本类型')">标本类型</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目 结果标志', '-1')">任意项目 结果标志</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('标本状态备注', '2')">标本状态备注</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目 仪器报警', '-1')">任意项目 仪器报警</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('报告单备注', '2')">报告单备注</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('任意项目代码', '-1')">任意项目代码</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('诊断', '2')"
                        @contextmenu.prevent.native="rightEvent('诊断')">诊断</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px" @click="operate('诊断ICD10', '2')"
                        @contextmenu.prevent.native="rightEvent('诊断ICD10')">诊断ICD10</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('仪器诊断', '-1')">仪器诊断</el-button>
                    </td>
                    <td colspan="2">
                      <el-button style="width: 135px;" @click="operate('条码号', '2')">条码号</el-button>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <el-button style="width: 100px; margin: 4px" @click="operate('分单类别', '2')"
                        @contextmenu.prevent.native="rightEvent('分单类别')">分单类别</el-button>
                    </td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
        </el-row>
      </el-form>
    </el-dialog>
    <!--备注说明双击弹窗编辑-->
    <el-dialog title="备注说明" :visible.sync="dialogcomment" :close-on-click-modal="false" width="500px">
      <div style="width: 100%; height: 200px; overflow: auto" :key="commentkey">
        <el-input v-model="comment" type="textarea" :rows="10" ref="refcomment"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="commentsave">确定</el-button>
        <el-button @click="dialogcomment = false">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="复制项目"
      :visible.sync="dialogCopyVisible">
      <table style="width: 100%">
        <tr>
          <td style="text-align: left">当前报告单元</td>
          <td>请选择需要复制的报告单元</td>
        </tr>
        <tr>
          <td style="text-align: left">
            {{ currentrptunitname }}
          </td>
          <td style="text-align: left">
            <el-select v-model="selrptunit"
              @dblclick.native="popMultipleChk(selrptunit, 'selrptunit', rptunitOption, '报告单元选择')" style="width: 100%"
              filterable clearable> <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data"
                :label="item.display"></el-option></el-select>
          </td>
        </tr>
        <tr>
          <td style="text-align: right" colspan="2">
            <el-button @click="CopyInstr()">确 定</el-button>
            <el-button @click="dialogCopyVisible = false">取消</el-button>
          </td>
        </tr>
      </table>
    </el-dialog>
    <!--多选弹窗--->
    <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle"
      :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
      <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname"
        @change="closedialog"></rm-SqlMultiple>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS138",
  data() {
    return {
      loading: false,
      outerVisible: false,
      okFirstLoading: false,
      dialogTableVisible: false,
      dialogx: false,
      dialogtitle: "",
      dataclass: "",
      rptunitid: "",
      rptunitname: "",
      dialogtopdata: "",
      dialogmiddledata: "",
      quicklysearch: "",
      itemclassname: "",
      mdlname: "",
      tempvarible: "",
      dialogsavedata: "",
      tempmiddata: "",
      curselectrow: "",
      tempindex: 0,
      actionindex: 0,
      selectrow: {},
      tableData: [],
      poptableData: [],
      poptempData: [],
      keyConfig: {
        isArrow: true,
        isDel: true,
        isTab: true,
        isEdit: true,
      },
      conditiontypeoptions: [
        { value: "0", label: "审核条件" },
        { value: "1", label: "自助打印条件" },
        { value: "8", label: "授权打印条件" },
        { value: "9", label: "绝对禁止审核" },
        { value: "7", label: "审核生成报告备注" },
        { value: "6", label: "审核条件需工号验证" },
        { value: "5", label: "审核生成实验室意见" },
      ],
      conditionarriveoptions: [
        { value: "0", label: "禁止" },
        { value: "1", label: "允许" },
        { value: "2", label: "生成" },
      ],
      dialogcomment: false,
      comment: "",
      commentkey: 0,
      option1: [],
      option2: [],
      fieldname: "",
      multichktitle: "",
      dialogCopyVisible: false,
      dialogMultipleVisible: false,
      rptunitOption: "",
      selrptunit: "",
      currentrptunitname: "",
    };
  },
  watch: {},
  created() {
    this.initoption();
    this.initialList(); //初始化主列表
    this.initialPopList(); //初始化弹窗列表
  },
  mounted() { },
  updated() {
    if (this.okFirstLoading) {
      let currentrow = "";
      if (this.actionindex != 0) {
        //新增，修改，删除
        if (this.actionindex == 3) {
          //如果是删除
          if (this.tempindex > 0) {
            currentrow = this.$refs.xTable.getData(this.tempindex);
          } else {
            currentrow = this.$refs.xTable.getData(0);
          }
        } else {
          //新增或修改
          if (this.actionindex == 2) {
            //修改
            if (this.curselectrow && this.curselectrow != "") {
              this.$nextTick(() => {
                let row = this.curselectrow;
                var alld = this.$refs.xTable.tableData;
                for (var i = 0; i < alld.length; i++) {
                  if (alld[i].ruleid == row.ruleid) {
                    this.tempindex = i;
                    break;
                  }
                }
                currentrow = this.$refs.xTable.getData(this.tempindex);
              });
            } else {
              currentrow = this.$refs.xTable.getData(0);
            }
          } else {
            //新增  actionindex=1
            if (this.ruleid && this.ruleid != "") {
              this.$nextTick(() => {
                var alld = this.$refs.xTable.tableData;
                for (var i = 0; i < alld.length; i++) {
                  if (alld[i].ruleid == this.ruleid) {
                    this.tempindex = i;
                    break;
                  }
                }
                currentrow = this.$refs.xTable.getData(this.tempindex);
              });
            } else {
              currentrow = this.$refs.xTable.getData(0);
            }
          }
        }
      } else {
        //查询
        currentrow = this.$refs.xTable.getData(0);
      }
      this.$nextTick(() => {
        if (currentrow) {
          this.okFirstLoading = false;
          this.comment = currentrow.logcontent;
          this.$refs.xTable.setCurrentRow(currentrow);
        }
      });
    }
  },
  methods: {
    CopyShow() {
      this.dialogCopyVisible = true;
      var rows = this.rptunitOption.filter((item) => item.data == this.rptunitid);
      if (rows.length > 0) this.currentrptunitname = rows[0].display;
      else this.currentrptunitname = this.rptunitid;
    },
    popMultipleChk(e, fieldname, option, title) {
      console.info("1111111");
      let temp = XEUtils.clone(option, true);
      this.option1 = [];
      this.option2 = [];
      if (e != "") {
        let k = e.split(",");
        k.forEach((item) => {
          let ndata = temp.find((m) => m.data == item);
          if (ndata != undefined && ndata != null) {
            this.option2.push(ndata);
          }
        });
        temp.forEach((item) => {
          if (k.indexOf(item.data + "") < 0) {
            this.option1.push(item);
          }
        });
      } else {
        this.option1 = temp;
      }
      this.fieldname = fieldname;
      this.multichktitle = title;
      this.dialogMultipleVisible = true;
    },
    closedialog(value, name) {
      if (value != "close") {
        this[name] = value;
      }
      this.dialogMultipleVisible = false;
    },
    CopyInstr() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS138",
          method: "post",
          data: {
            action: "copy",
            sourcerptunitid: this.rptunitid,
            targetrptunitids: this.selrptunit,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.$message({
              message: "复制成功",
              type: "success",
            });
            this.dialogCopyVisible = false;
          } else {
            this.$alert(res.errmsg, "错误");
          }
        });
    },
    initialList() {
      this.loading = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS138",
          method: "post",
          data: {
            action: "query",
            rptunitid: this.rptunitid,
          },
        })
        .then((response) => {
          this.tableData = response.Data;
          if (this.tableData.length > 0) this.curselectrow = this.tableData[0];
          this.loading = false;
          this.okFirstLoading = true;
        })
        .catch((e) => {
          this.loading = false;
          alert(e);
        });
    },
    initoption() {
      this.$tool
        .request({
          url: "LIS/LIS1/LIS138",
          method: "post",
          data: {
            action: "initoption",
          },
        })
        .then((res) => {
          this.rptunitOption = res.rptunitOption;
        })
        .catch((e) => {
          alert(e);
        });
    },
    initialPopList() {
      this.loading = true;
      this.$tool
        .request({
          url: "LIS/LIS1/LIS138",
          method: "post",
          data: {
            action: "queryrptitem",
            rptunitid: this.rptunitid,
          },
        })
        .then((response) => {
          this.poptableData = response.Data;
          this.poptempData = XEUtils.clone(response.Data, true);
          this.loading = false;
        })
        .catch((e) => {
          this.loading = false;
          alert(e);
        });
    }, //主列表行选中
    currentChangeEvent({ row, $rowIndex }) {
      this.tempindex = $rowIndex;
      this.actionindex = 2; //修改
      this.curselectrow = row;
    }, //弹窗列表行选中
    handerinvalide(row) {
      row.logflag = row.logflag == "1" ? 0 : 1;
    },
    rowClassName({ row, rowIndex }) {
      let isDirty = this.$refs.xTable.hasRowChange(row);
      if (isDirty) {
        return "row-modify";
      }
      if (this.$refs.xTable.hasRowInsert(row)) return "row-new";
    },
    operatemdl(k) {
      if (k == 1) {
        //新增
        let initdata = {
          checktype: "0",
          actions: "0",
          ruledisplay: "",
          logcontent: "",
          logflag: "0",
          checkrules: "",
          onlyautochk: "0",
        };
        this.$refs.xTable.insert(initdata).then(({ row }) => {
          this.curselectrow = row;
        });
        this.actionindex = 1; //新增
        this.FunScrollY();
        let rows = this.$refs.xTable.tableData;
        let selectrow = this.$refs.xTable.tableData[rows.length - 1];
        if (selectrow && selectrow != "") {
          this.$refs.xTable.setCurrentRow(selectrow);
          this.$refs.xTable.setActiveRow(selectrow, "checktype");
        }
      } else {
        //删除
        try {
          var delrow = this.$refs.xTable.getCurrentRow();
          if (delrow) {
            var alld = this.$refs.xTable.tableData;
            var rowindex = alld.indexOf(delrow);
            this.$refs.xTable.remove(delrow);
            this.actionindex = 3; //新增
            let havedata = this.$refs.xTable.tableData;
            if (havedata.length > 0) {
              if (rowindex >= havedata.length) rowindex = havedata.length - 1;
              let selectrow = havedata[rowindex];
              this.$refs.xTable.setCurrentRow(selectrow);
            }
          }
        } catch (e) {
          console.log("error", e);
        }
      }
    },
    FunScrollY() {
      this.$nextTick(() => {
        var alldataLen = this.$refs.xTable.tableData.length;
        let L = this.$refs.xTable.getTableData().fullData[alldataLen - 1];
        this.$refs.xTable.scrollToRow(L);
      });
    },
    ExportCsv() {
      this.$refs.xTable.exportCsv({ filename: "报告单元组合审核条件" });
    },
    EditClose({ row, column, rowIndex }) {
      if (column.property == "logcontent") {
        this.$refs.xTable.$refs.tableBody.$children[rowIndex].$el.focus();
      }
    }, //回车增加行暂时注释，当前点击第二行会把组合条件置空
    CellActive({ row, rowIndex, column }) {
      // let lenindex = this.$refs.xTable.tableData.length;
      // if (rowIndex + 1 == lenindex) {
      //     if (column.property == "checktype") {
      //         if (rowIndex > 0) {
      //             row.checktype = "0";
      //             row.actions = "0";
      //             row.logflag = "0";
      //             row.ruledisplay = "";
      //             row.logcontent = "";
      //             row.checkrules = "";
      //         }
      //         this.FunScrollY();
      //         let rows = this.$refs.xTable.tableData;
      //         let selectrow = this.$refs.xTable.tableData[rows.length - 1];
      //         if (selectrow && selectrow != "") {
      //             this.$refs.xTable.setCurrentRow(selectrow);
      //             this.$refs.xTable.setActiveRow(selectrow, "checktype");
      //         }
      //     }
      // }
    },
    saverecord() {
      let data = this.$refs.xTable.tableData;
      let fdata = data.filter((item) => item.ruledisplay == "");
      if (fdata.length > 0) {
        //查找是否有组合条件为空的数据
        this.$alert("检测到组合条件为空的数据，请填写后保存或者删除空数据后保存！", "提示");
      } else {
        let tabledata = this.$refs.xTable.getRecordset();
        this.$tool
          .request({
            url: "LIS/LIS1/LIS138",
            method: "post",
            data: {
              action: "save",
              rptunitid: this.rptunitid,
              urecstr: tabledata,
            },
          })
          .then((response) => {
            if (response.errcode == "1") {
              this.$message({
                message: "操作成功！",
                type: "success",
              });
              this.initialList();
              this.ruleid = response.ruleid;
            } else {
              this.$message({
                message: "保存失败！",
                type: "warning",
              });
            }
          });
      }
    },
    opendialog({ row, column }) {
      if (column.property == "ruledisplay" || column.property == "checkrules") {
        this.outerVisible = true;
        this.selectrow = row;
        if (row.ruledisplay == null) {
          row.ruledisplay = "";
        }
        this.dialogtopdata = row.ruledisplay;
        this.dialogmiddledata = row.checkrules;
        this.initialPopList(); //初始化弹窗列表
      } else if (column.property == "logcontent") {
        this.comment = row.logcontent;
        this.dialogcomment = true;
        this.commentkey++;
        if (this.$refs.refcomment)
          setTimeout(() => {
            this.$refs.refcomment.focus();
          }, 10);
      }
    },
    commentsave() {
      console.log(this.curselectrow);
      console.log(this.comment);
      this.curselectrow.logcontent = this.comment;
      this.dialogcomment = false;
    },
    operate(text, type) {
      //按钮选中
      if (type == "1") {
        this.tempvarible = " " + text + " ";
      } else if (type == "2") {
        this.tempvarible = " " + '"' + "[" + text + "]" + '"' + " ";
      } else {
        this.tempvarible = " " + "[" + text + "]" + " ";
      }
      if (this.dialogmiddledata != "") {
        //如果是新增
        if (type == "1") {
          this.tempvarible = text;
        } else if (type == "2") {
          this.tempvarible = '"' + "[" + text + "]" + '"';
        } else {
          this.tempvarible = "[" + text + "]";
        }
        var myValue = this.tempvarible;
        this.HightlightPos(myValue);
      } else {
        this.dialogtopdata += this.tempvarible;
        this.dialogmiddledata += this.tempvarible;
      }
      this.ConvertMiddatatoTopdata();
      const h = this.$createElement;
      let k = false;
      let popstr = "";
      if (text == "性别") {
        popstr = "1：男 2：女";
        k = true;
      } else if (text == "病人类型") {
        popstr = "1:门诊，2：急诊，3：住院，4：体检，其他请查看字典中的设定";
        k = true;
      } else if (text == "科室") {
        popstr = "鼠标右键点击可选择 科室代码";
        k = true;
      } else if (text == "标本类型") {
        popstr = "鼠标右键点击可选择 标本类型";
        k = true;
      } else if (text == "诊断") {
        popstr = "鼠标右键点击可选择 诊断文字";
        k = true;
      } else if (text == "诊断ICD10") {
        popstr = "鼠标右键点击可选择 诊断ICD10";
        k = true;
      } else {
      }
      if (k) {
        this.$message({
          message: h("p", null, [h("span", null, text), h("i", { style: "color: teal" }, popstr)]),
        });
      }
    },
    async savedialog() {
      try {
        const res = await this.$tool.request({
          url: "LIS/LIS1/LIS138",
          method: "post",
          data: {
            action: "checkcalcformula",
            checkrules: this.dialogmiddledata,
          },
        });
        if (res.msg != "") {
          this.$alert(res.msg, "出错");
        } else {
          this.selectrow.ruledisplay = this.dialogtopdata;
          this.selectrow.checkrules = this.dialogmiddledata;
          this.outerVisible = false;
        }
      } catch (e) {
        this.$alert(e, "出错");
      }
    },
    rightEvent(event) {
      this.dialogx = false;
      if (event == "科室") {
        this.dialogtitle = "请选择科室";
        this.dataclass = "dept";
      } else if (event == "标本类型") {
        this.dialogtitle = "请选择标本类型";
        this.dataclass = "specimen";
      } else if (event == "诊断") {
        this.dialogtitle = "请选择诊断";
        this.dataclass = "diagnose";
      } else if (event == "诊断ICD10") {
        this.dialogtitle = "请选择诊断ICD10";
        this.dataclass = "diagnose";
      } else if (event == "分单类别") {
        this.dialogtitle = "请选择分单类别";
        this.dataclass = "reqgroup";
      } else {
      }
      this.dialogx = true;
      this.dialogTableVisible = true;
    },
    cancelinnerdialog() {
      this.dialogTableVisible = false;
      this.dialogx = false;
    },
    HightlightPos(myValue) {
      var myField = document.getElementById("middiv"); //this.$refs.singleText;
      if (myField.selectionStart || myField.selectionStart === 0) {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        this.dialogmiddledata = myField.value.substring(0, startPos) + " " + myValue + " " + myField.value.substring(endPos, myField.value.length);
        this.$nextTick(() => {
          myField.selectionStart = startPos + myValue.length + 2;
          myField.selectionEnd = startPos + myValue.length + 2;
        }); // 这句是重点, 圈起来
        myField.focus();
        myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
      } else {
        this.dialogmiddledata += " " + myValue + " ";
      }
    },
    popcurrentChangeEvent({ row }) {
      //弹窗行选中事件
      let myValue = "[" + row.rpt_itemcode + "]";
      this.HightlightPos(myValue);
      this.ConvertMiddatatoTopdata();
    },
    targetinput() {
      this.ConvertMiddatatoTopdata();
    },
    ConvertMiddatatoTopdata() {
      let middata = this.dialogmiddledata;
      let arr = middata.split(" ");
      let TopString = [];
      for (var i = 0, len = arr.length; i < len; i++) {
        let temp = "";
        let element = arr[i];
        if (element != "") {
          if (element.indexOf("[") > -1 && element.indexOf("]") > -1) {
            let tpel = this.getBracketStr(element);
            let xtable = this.$refs.xTable2.tableData;
            try {
              xtable.forEach((element) => {
                let item = element.rpt_itemcode + "_" + element.itemcode_en;
                if (item.indexOf(tpel) > -1) {
                  let itemdata = item.split("_");
                  let rpt_itemcode = itemdata[0];
                  let itemcode_en = itemdata[1];
                  if (rpt_itemcode == tpel) temp = "[" + itemcode_en + "]";
                  throw Error();
                }
              });
            } catch (e) { }
            if (temp == "") {
              temp = element;
            }
          } else {
            temp = element;
          }
        } else {
          temp = element;
        }
        TopString.push(temp);
      }
      this.dialogtopdata = TopString.join(" ");
    },
    getBracketStr(text) {
      let result = "";
      let regex = /\[(.+?)\]/g;
      let options = text.match(regex);
      let option = options[0];
      result = option.substring(1, option.length - 1);
      return result;
    },
    popcomchange(c, v) {
      //"选择后code", c//"选择后name", v
      this.dialogx = false;
      if (this.dialogmiddledata != "") {
        //如果是新增
        var myValue = "";
        if (this.dataclass == "dept" || this.dataclass == "specimen" || this.dataclass == "reqgroup") {
          myValue = '"' + c + '"';
        } else {
          myValue = '"' + v + '"';
        }
        this.HightlightPos(myValue);
      } else {
        //修改
        if (this.dataclass == "dept" || this.dataclass == "specimen" || this.dataclass == "reqgroup") {
          this.dialogtopdata += " " + '"' + c + '"' + " ";
          this.dialogmiddledata += " " + '"' + c + '"' + " ";
        } else {
          this.dialogtopdata += " " + '"' + v + '"' + " ";
          this.dialogmiddledata += " " + '"' + v + '"' + " ";
        }
      }
      this.ConvertMiddatatoTopdata();
      this.dialogTableVisible = false;
    },
    rptunitchange(code, name) {
      this.rptunitid = code;
      this.initialList();
    },
    PopListSearch() {
      let record = [];
      this.quicklysearch = this.quicklysearch.trim();
      if (this.quicklysearch != "") {
        record = this.poptempData.filter((item) => {
          return item.rpt_itemcode == null ? false : item.rpt_itemcode.toUpperCase().indexOf(this.quicklysearch.toUpperCase()) > -1 || item.rpt_itemname.indexOf(this.quicklysearch) > -1 || item.itemcode_en.toUpperCase().indexOf(this.quicklysearch.toUpperCase()) > -1;
        });
      } else {
        record = XEUtils.clone(this.poptempData, true);
      }
      this.poptableData = record;
      this.tempindex = 0;
      this.actionindex = 0;
    },
  },
};
</Script>

<style scoped>.pagetop {
  width: 100%;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}

::deep .middle-center tr.vxe-body--row.row-modify {
  color: blue !important;
}</style>